﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace LILI.Data.DAL
{
    public class D_Article
    {
        #region  Method

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LILI.Data.Model.M_Article model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Article_Info(");
            strSql.Append("ArticleTypeID,ArticleTitle,ArticleCotent,ViewsCount,PublishDate)");
            strSql.Append(" values (");
            strSql.Append("@ArticleTypeID,@ArticleTitle,@ArticleCotent,@ViewsCount,@PublishDate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@ArticleTypeID", SqlDbType.Int,4),
					new SqlParameter("@ArticleTitle", SqlDbType.NVarChar,30),
					new SqlParameter("@ArticleCotent", SqlDbType.Text),
					new SqlParameter("@ViewsCount", SqlDbType.Int,4),
					new SqlParameter("@PublishDate", SqlDbType.DateTime)};
            parameters[0].Value = model.ArticleTypeID;
            parameters[1].Value = model.ArticleTitle;
            parameters[2].Value = model.ArticleCotent;
            parameters[3].Value = model.ViewsCount;
            parameters[4].Value = model.PublishDate;
            int i = DataHelper.ExecuteScalar<int>(strSql.ToString(), parameters);
            return i;
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ArticleID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Article_Info ");
            strSql.Append(" where ArticleID=@ArticleID");
            SqlParameter[] parameters = {
					new SqlParameter("@ArticleID", SqlDbType.Int,4)
            };
            parameters[0].Value = ArticleID;
            int rows = DataHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion  Method
    }
}
